package myschool.test;

import myschool.dao.SubjectDao;
import myschool.entity.Subject;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author oldliu
 * @since 1.0
 */
public class DelSubject {
    public static void main(String[] args) {
        try {
            String resource = "mybatis-config.xml";
            Reader reader = null;
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(reader);
            SqlSession session = sf.openSession();//Connetion:true:自动提交
            SubjectDao mapper = session.getMapper(SubjectDao.class);
            int del = mapper.del(57L);
            System.out.println("delete了几行？"+del);
            session.commit();//提交一下事务
            session.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
